package com.atguigu.gmall.secKill.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.secKill.pojo.UserRecode;
import com.atguigu.gmall.secKill.service.SecKillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author ZengMing
 * @Date 2021/7/16 19:29
 * @Description:秒杀订单业务controller
 */
@RequestMapping(value = "/secKill/order")
@RestController
public class SeckillOrderController {

    @Autowired
    private SecKillService seckillService;

    /**
     * 秒杀下单
     * @param skuId
     * @param time
     * @return
     */
    @GetMapping(value = "/add")
    public Result addSeckillOrder(String skuId, String time){
        String username = "zengming";
        UserRecode userRecode = seckillService.addOrder(time, skuId, username);
        return Result.ok(userRecode);
    }

    /**
     * 查询用户的排队信息
     * @return
     */
    @GetMapping(value = "/getRecode")
    public Result getUserRecode(){
        String username = "zengming";
        UserRecode userRecode = seckillService.getUserRecode(username);
        return Result.ok(userRecode);
    }

    /**
     * 查询秒杀订单的信息
     * @param orderId
     * @return
     */
    @GetMapping(value = "/getSeckillOrder")
    public Result getSeckillOrder(String orderId){
        String username = "zengming";
        return Result.ok(seckillService.getSeckillOrderList(username,orderId));
    }
}
